package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.mapper.CarMapper;
import com.qf.pojo.Car;
import com.qf.service.CarService;
import com.qf.vo.CarList;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CarServiceImpl implements CarService {
    @Resource
    private CarMapper carMapper;

    @Override
    public PageInfo<Car> findAll (int page) {
        PageHelper.startPage (page,4);
        List<Car> allCar = carMapper.findAllCar ();
        PageInfo<Car> carPageInfo = new PageInfo<> (allCar);
        return carPageInfo;
    }

    @Override
    public CarList findAllBy (int cid) {
        List<Car> number = carMapper.findAllOrderByNumber (cid);
        List<Car> price = carMapper.findAllOrderByPrice (cid);
        return new CarList (price,number);
    }

    @Override
    public Car findOneCar(int cid) {
        return carMapper.findOneCar(cid);
    }

    @Override
    public Car add (Car car) {
        carMapper.add(car);
        return car;
    }

    @Override
    public int update (Car car) {
        return carMapper.update(car);
    }

    @Override
    public int delete (int id) {
        return carMapper.delete(id);
    }
}
